cd "C:\Users\rodin\VenAnalytics Dropbox\VenAnalytics\Research\Papers\2022\Effects of Sanctions\ANOVA\"

use "Paper\DatasetUpdateV2.dta", clear

log using anova4.smcl,replace

gen t=x

mat A=J(7,3,.)
mat B=J(10,3,.)


gen dum=0
replace dum=1 if t>=0
gen tdum=0
replace tdum=t if t>=0
tokenize foodanova foodanovaextended foodbaharetal medicines availablefoodanova availablefoodanovaextended availablefoodbaharetal availablemedicines

forvalues i=1/8	{
replace ``i''=``i''/1000000
	
}



rename foodanova fooda
rename foodanovaextended foodax
rename foodbaharetal foodb
rename medicines meds
rename availablefoodanova foodaa
rename availablefoodanovaextended foodaxa
rename availablefoodbaharetal foodba
rename availablemedicines medsa

gen lfooda=ln(fooda)
gen lfoodax=ln(foodax)
gen lfoodb=ln(foodb)
gen lmeds=ln(meds)
gen lfoodaa=ln(foodaa)
gen lfoodaxa=ln(foodaxa)
gen lfoodba=ln(foodba)
gen lmedsa=ln(medsa)


*** Table 1: Trend Break Specifications ***

* Levels * 

fit foodaa dum tdum t, robust
estimates store est1
fit foodba dum tdum t, robust
estimates store est2
fit medsa dum tdum t, robust
estimates store est3

* Logarithms * 

fit lfoodaa dum tdum t, robust
estimates store est4
fit lfoodba dum tdum t, robust
estimates store est5
fit lmedsa dum tdum t, robust
estimates store est6

* August 2022 data * 

fit lfooda dum tdum t, robust
estimates store est7
fit lfoodb dum tdum t, robust
estimates store est8
fit lmeds dum tdum t, robust
estimates store est9

fit fooda dum tdum t, robust
estimates store est7a
fit foodb dum tdum t, robust
estimates store est8a
fit meds dum tdum t, robust
estimates store est9a

estimates table est1 est2 est3 est4 est5 est6 est7 est8 est9, se p

estimates table est7a est8a est9a, se p





graph twoway (lfitci foodaa t if t<=0, lwidth(thick) legend(off))  (lfitci foodaa t if t>0, lwidth(thick)) (scatter foodaa t, mfcolor(white) msize(small)), xscale(range(-40 40)) title("Equipo Anova (excludes cereals and oils)") saving(fig1.gph, replace) scale(0.8)
graph twoway (lfitci foodb t if t<=0, lwidth(thick) legend(off))  (lfitci foodb t if t>0 & t<=28, lwidth(thick)) (scatter foodb t if t<=0, mfcolor(white) msize(small)), xscale(range(-40 40)) title("Including cereals and oils") saving(fig2.gph, replace)  scale(0.8)
graph twoway (lfitci lfoodb t if t<=0, lwidth(thick) legend(off))  (lfitci lfoodb t if t>0 & t<=28, lwidth(thick)) (scatter lfoodb t if t<=28, mfcolor(white) msize(small)), xscale(range(-40 40)) title("Including cereals and oils, logs") saving(fig3.gph, replace) scale(0.8)
graph combine fig1.gph fig3.gph, rows(1) saving(figure1.gph, replace)




graph twoway (lfit foodaa t if t<=0,  lwidth(thick) legend(off)) (lfit foodaa t if t<=0, range(0 28) lpattern(dash) lcolor(navy) legend(off)) (lfit foodaa t if t>0, lwidth(thick)) (scatter foodaa t, mfcolor(none) msize(small)), yscale(range(-300 300)) xscale(range(-40 40)) title("Food") saving(fig6.gph, replace)  yline(0, lcolor(black))
graph twoway (lfit medsa t if t<=0,  lwidth(thick) legend(off) ) (lfit medsa t if t<=0, range(0 28) lpattern(dash) lcolor(navy) legend(off)) (lfit medsa t if t>0, lwidth(thick)) (scatter medsa t, mfcolor(none) msize(small)),  xscale(range(-40 40)) title("Medicines") saving(fig7.gph, replace)  yline(0, lcolor(black))

graph combine  fig6.gph fig7.gph, saving(figure2.gph, replace)




graph twoway (lfitci lmeds t if t<=0,  lwidth(thick) legend(off) )  (lfitci lmeds t if t>0 & t<=28 , lwidth(thick)) (scatter lmeds t if t<=28, mfcolor(none) msize(small)),  xscale(range(-40 40)) saving(figure3.gph, replace)  yline(0, lcolor(black)) text(5.5 -18 "lnm=2.73-.09*t", size(small) color(navy)) text(5.35 -14 "(.01)", size(small) color(navy)) text(3 35 "lnm=2.43+.01*t", size(small) color(maroon)) text(2.85 39 "(.01)", size(small) color(maroon)) 





*** TABLE 3 ***


fit imagefood dum tdum t, robust
estimates store est15

fit imagemedicines dum tdum t, robust
estimates store est16


estimates table est15 est16, se p


tabstat foodaa medsa imagefood imagemedicines, by(dum) stats(mean) save


corr imagefood foodaa

mat B[10,1]=r(rho)
corr imagemedicines medsa
mat B[10,2]=r(rho)
svmat B

keep  B*
save results.dta, replace



use MasterDataset2013.dta, clear
*gen year=int(period/100)
rename foodanova fooda
rename foodanovaextended foodax
rename foodbaharetal foodb
rename medicines meds
rename availablefoodanova foodaa
rename availablefoodanovaextended foodaxa
rename availablefoodbaharetal foodba
rename availablemedicines medsa


tabstat fooda foodax foodb meds if year<=2021, by(year) format(%12.0g) stats(sum)

gen essentials=foodb+meds
tabstat ess if year<=2021, by(period) format(%12.0g)

use results.dta, clear


use "Paper\DatasetUpdate2012.dta", clear


gen t=x

mat A=J(7,3,.)
mat B=J(10,3,.)


tokenize foodanova foodanovaextended foodbaharetal medicines 

forvalues i=1/4	{
replace ``i''=``i''/1000000
	
}

rename foodanova fooda
rename foodanovaextended foodax
rename foodbaharetal foodb
rename medicines meds


gen lfooda=ln(fooda)
gen lfoodax=ln(foodax)
gen lfoodb=ln(foodb)
gen lmeds=ln(meds)


*** Table 2: Current Data ***

rdrobust lfoodax t if t<=40, c(0) all
estimates store est7
rdrobust lfoodax t if t<=40, c(0) deriv(1) all
estimates store est8
rdrobust lfooda t if t<=40, c(0) all
estimates store est9 
rdrobust lfooda t if t<=40, c(0) deriv(1) all
estimates store est10
rdrobust lfoodb t if t<=40, c(0) all
estimates store est11
rdrobust lfoodb t if t<=40, c(0) deriv(1) all
estimates store est12
rdrobust lmeds t if t<=40, c(0) all
estimates store est13 
rdrobust lmeds t if t<=40, c(0) deriv(1) all
estimates store est14

estimates table est7 est8 est9 est10 est11 est12 est13 est14, se p

log close